package com.azu.bitmapworker.common;

import android.app.FragmentManager;
import android.content.Context;

import com.azu.bitmapworker.core.BitmapDisplayConfig;
import com.azu.bitmapworker.core.BitmapWorker;
import com.azu.bitmapworker.utils.Utils;

/**
 * Created by zhangmian on 14-1-17.
 */
public class CommonBitmapWorkerFactory {

	private static final String DISK_CACHE_DIR = "Common";
	private static final int DISK_CACHE_SIZE = 30 * 1024 * 1024;
	private static final int POOL_SIZE = 2;

	public static BitmapWorker createBitmapWorker(Context context, FragmentManager fragmentManager, BitmapDisplayConfig displayConfig) {
		CommonBitmapCache.Config cacheConfig = new CommonBitmapCache.Config();
		cacheConfig.diskCacheDir = Utils.getDiskCacheDir(context, DISK_CACHE_DIR);
		cacheConfig.diskCacheSize = DISK_CACHE_SIZE;
		cacheConfig.setMemCacheSizePercent(context, 0.5f);
		CommonBitmapCache cache = CommonBitmapCache.getInstance(fragmentManager, cacheConfig);
		BitmapWorker.BitmapWorkerConfig config = new BitmapWorker.BitmapWorkerConfig(context.getResources());
		config.processor = new CommonBitmapProcessor();
		config.loader = new CommonBitmapLoader(context, cache);
		config.poolSize = POOL_SIZE;
		config.displayer = new CommonBitmapDisplayer();
		config.defaultDisplayConfig = displayConfig;
		return createBitmapWorker(context, cache, config);
	}

	public static BitmapWorker createBitmapWorker(Context context, CommonBitmapCache cache, BitmapWorker.BitmapWorkerConfig config) {
		BitmapWorker worker = new BitmapWorker(context, config, cache);
		return worker;
	}
}
